Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-done

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-done

Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is async-done?

The async-done npm package is a utility for handling asynchronous tasks in Node.js. It provides a simple way to manage callbacks, promises, observables, and streams, making it easier to work with various types of asynchronous operations.

What are async-done's main functionalities?

Handling Callbacks

This feature allows you to handle asynchronous tasks that use callbacks. The `asyncDone` function takes a task function and a callback to handle the result or error.

const asyncDone = require('async-done');

function callbackTask(done) {
  setTimeout(() => {
    done(null, 'Callback Task Completed');
  }, 1000);
}

asyncDone(callbackTask, (err, result) => {
  if (err) throw err;
  console.log(result); // Output: Callback Task Completed
});

Handling Promises

This feature allows you to handle asynchronous tasks that return promises. The `asyncDone` function can manage the promise and handle the result or error.

const asyncDone = require('async-done');

function promiseTask() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('Promise Task Completed');
    }, 1000);
  });
}

asyncDone(promiseTask, (err, result) => {
  if (err) throw err;
  console.log(result); // Output: Promise Task Completed
});

Handling Observables

This feature allows you to handle asynchronous tasks that return observables. The `asyncDone` function can manage the observable and handle the result or error.

const asyncDone = require('async-done');
const { Observable } = require('rxjs');

function observableTask() {
  return new Observable((observer) => {
    setTimeout(() => {
      observer.next('Observable Task Completed');
      observer.complete();
    }, 1000);
  });
}

asyncDone(observableTask, (err, result) => {
  if (err) throw err;
  console.log(result); // Output: Observable Task Completed
});

Handling Streams

This feature allows you to handle asynchronous tasks that return streams. The `asyncDone` function can manage the stream and handle the result or error.

const asyncDone = require('async-done');
const { Readable } = require('stream');

function streamTask() {
  const stream = new Readable();
  stream._read = () => {};
  setTimeout(() => {
    stream.push('Stream Task Completed');
    stream.push(null);
  }, 1000);
  return stream;
}

asyncDone(streamTask, (err, result) => {
  if (err) throw err;
  console.log(result); // Output: Stream Task Completed
});

Other packages similar to async-done

Keywords

FAQs

Package last updated on 09 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc